package cn.hd01.repository;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.hd01.repository.entity.RebateSummary;

@Repository
public interface RebateSummaryRepository extends JpaRepository<RebateSummary, Integer> {
	Page<RebateSummary> findAll(Specification<RebateSummary> spec, Pageable pageable);
	
	RebateSummary findByRefIdAndType(Integer refId, String type);

	@Query(value="select sum(allRebate) as allRebate, sum(allWithdrawRebate) as allWithdrawRebate from RebateSummary")
	List<Object[]> findSummary();
	
	@Query("SELECT SUM(allRebate) AS allRebate, SUM(allWithdrawRebate) AS allWithdrawRebate FROM RebateSummary WHERE refId IN (SELECT id FROM Customer WHERE TYPE = 1 AND recommendDistributorId = ?1)")
	List<Object[]> findOtherSummary(Integer distributorId);
}
